//
//  DoctorView.m
//  QuickCure
//
//  Created by Cyan on 16/9/12.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "DoctorView.h"

#import "DoctorListModel.h"

@interface DoctorView ()
/**
 *  医生头像图片
 */
@property (nonatomic, strong) UIImageView *doctorIcon;
/**
 *  医生名字 label
 */
@property (nonatomic, strong) UILabel *nameLabel;
/**
 *  医生职务 label
 */
@property (nonatomic, strong) UILabel *postLabel;
/**
 *  医生所属医院
 */
@property (nonatomic, strong) UILabel *hosLabel;
/**
 *  操作数
 */
@property (nonatomic, strong) UIButton *plusButton;
/**
 *  鲜花数
 */
@property (nonatomic, strong) UIButton *flowerButton;
/**
 *  星星数
 */
@property (nonatomic, strong) UIButton *starButton;



@end

@implementation DoctorView
#pragma mark - 快速创建对象方法
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        [self addMySubviews];
        
    }
    return self;
}

#pragma mark - 设置数据
- (void)setModel:(DoctorListModel *)model {
    _model = model;
    
    
    self.nameLabel.text = model.doctor_name;
    
    self.postLabel.text = model.doctor_title_name;
    
    self.hosLabel.text = model.hospital_name;
    
    
    [self.plusButton setTitle:[NSString stringWithFormat:@"%ld",model.flower.integerValue] forState:UIControlStateNormal];
    
    [self.starButton setTitle:[NSString stringWithFormat:@"%ld",model.operation_count.integerValue] forState:UIControlStateNormal];
    
    
    [self.flowerButton setTitle:[NSString stringWithFormat:@"%ld",model.doctor_attention_id.integerValue] forState:UIControlStateNormal];
    
    
}

 #pragma mark - 设置控件约束
- (void)addMySubviews {
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@5);
        make.leading.equalTo(self);
        make.trailing.equalTo(self);
        make.bottom.equalTo(self);
    }];
    
    [self.doctorIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.leading.equalTo(self).offset(20);
        make.width.equalTo(@80);
        make.height.equalTo(@80);
    }];
    
    // doctor's name
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_doctorIcon.mas_trailing).offset(5);
        make.top.equalTo(self).offset(20);
    }];
    
    // doctor's post
    [self.postLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_nameLabel.mas_bottom);
        make.leading.equalTo(_nameLabel.mas_trailing).offset(10);
    }];
    // doctor's hospital
    [self.hosLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_doctorIcon.mas_trailing).offset(5);
        make.top.equalTo(_nameLabel.mas_bottom).offset(10);
    }];

    // doctor's operation Count
    [self.plusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).offset(30);
        make.top.equalTo(_doctorIcon.mas_bottom).offset(15);
        make.width.equalTo(@50);
    }];
    
    
    // doctor's flower
    [self.flowerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_plusButton.mas_bottom);
//        make.leading.equalTo(_plusButton.mas_trailing).offset(50);
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@60);
    }];
    [self.starButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_flowerButton.mas_bottom);
        make.width.equalTo(@50);
        make.trailing.equalTo(self).offset(-30);
    }];

    
    
}

#pragma mark - 控件懒加载
// starButton(doctor got stars)
-(UIButton *)starButton {
    
    if (!_starButton) {
        _starButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:_starButton];
        
        [_starButton setTitleColor:kThemeColor forState:UIControlStateNormal];
        [_starButton setImage:[UIImage imageNamed:@"jinqi"] forState:UIControlStateNormal];
        //        [_starButton setBackgroundColor:[UIColor greenColor]];
        [_starButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
        [_starButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        
    }
    return _starButton;
}


// flowerButton(doctor's flowers)
-(UIButton *)flowerButton {
    if (!_flowerButton) {
        _flowerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:_flowerButton];
        [_flowerButton setTitleColor:kThemeColor forState:UIControlStateNormal];
        [_flowerButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        
        [_flowerButton setImage:[UIImage imageNamed:@"xianhua"] forState:UIControlStateNormal];
        //        [_flowerButton setBackgroundColor:[UIColor yellowColor]];
        [_flowerButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
    }
    
    return _flowerButton;
}


// plusButton
- (UIButton *)plusButton {
    if (!_plusButton) {
        
        _plusButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:_plusButton];
        [_plusButton setTitleColor:kThemeColor forState:UIControlStateNormal];
        [_plusButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [_plusButton setImage:[UIImage imageNamed:@"yuyueliang"] forState:UIControlStateNormal];
        //        [_plusButton setBackgroundColor:[UIColor redColor]];
        [_plusButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
        
        
    }
    return _plusButton;
}






// hosLabel
- (UILabel *)hosLabel {
    
    if (!_hosLabel) {
        _hosLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:_hosLabel];
        _hosLabel.numberOfLines = 2;
        _hosLabel.textAlignment = NSTextAlignmentLeft;
        _hosLabel.textColor = [UIColor lightGrayColor];
        _hosLabel.font = [UIFont systemFontOfSize:18];
        
    }
    return _hosLabel;
}

// postLabel
- (UILabel *)postLabel {
    if (!_postLabel) {
        _postLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:_postLabel];
        
        _postLabel.textColor = [UIColor lightGrayColor];
        _postLabel.textAlignment = NSTextAlignmentLeft;
        _postLabel.font = [UIFont systemFontOfSize:16];
        
    }
    return _postLabel;
}


// nameLabel
- (UILabel *)nameLabel {
    
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = [UIFont systemFontOfSize:18];
        [self addSubview:_nameLabel];
    }
    return _nameLabel;
}


// doctorIcon
- (UIImageView *)doctorIcon {
    
    if (!_doctorIcon) {
        _doctorIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        
        _doctorIcon.image = [UIImage imageNamed:@"illness_img_person.png"];
        
        [_doctorIcon sizeToFit];
        
        [self addSubview:_doctorIcon];
    }
    return _doctorIcon;
}

@end

